/*-----------------------------------------------------------------------------
    
    Copyright (C) 2009 ALi Corp. All rights reserved.
    
    File: nim_m3101_init.c
    
    Content: Implement driver init routines.
    
    History: 
    2009/3/28 by Wing
        Created this file based on "nim_m3101.c" to refactor the driver.It still
        implements "nim_m3101_attch", "nim_m3101_attach_ext", "nim_m3101_attach_fn", 
        and "nim_m3101_attach_ext_fn" to keep compatible with the old drivers.
        These functions are just a wrapper for function "nim_m31_attach", that 
        is more flexible for future use.
-----------------------------------------------------------------------------*/
#include <sys_config.h>
#include <retcode.h>
#include <types.h>
#include <osal/osal.h>
#include <api/libc/alloc.h>
#include <api/libc/printf.h>
#include <api/libc/string.h>
#include <hal/hal_gpio.h>
#include <hld/hld_dev.h>
#include <hld/nim/nim_dev.h>
#include <hld/nim/nim.h>
#include <hld/nim/nim_tuner.h>      
#include <bus/i2c/i2c.h>
#include <bus/tsi/tsi.h>

#include "nim_m3101.h"

#define M3100_REV_ID        4

static const char *nim_dev_name[] = 
{
    "NIM_COFDM_0", 
    "NIM_COFDM_1", 
};

// Old interface for COFDM_M3101
INT32 nim_m3101_attach(PCOFDM_TUNER_CONFIG_API pConfig)
{
#if (SYS_TUN_MODULE == ANY_TUNER)
    pConfig->tuner_type = SYS_TUN_TYPE;
#else
    pConfig->tuner_type = SYS_TUN_MODULE;
#endif
    pConfig->rev_id = sys_ic_M3101_rev_id();
    pConfig->config_mode = 0;
    pConfig->work_mode = NIM_COFDM_SOC_MODE;
    nim_m31_attach(nim_dev_name[0], pConfig);
}

INT32 nim_m3101_attach_ext(PCOFDM_TUNER_CONFIG_API pConfig)
{
#if (SYS_TUN_MODULE == ANY_TUNER)
    pConfig->tuner_type = SYS_TUN_TYPE;
#else
    pConfig->tuner_type = SYS_TUN_MODULE;
#endif
    pConfig->rev_id = sys_ic_M3101_rev_id();
    pConfig->config_mode = 1;
    pConfig->work_mode = NIM_COFDM_SOC_MODE;
    nim_m31_attach(nim_dev_name[0], pConfig);
}

// Old interface for COFDM_M3100
INT32 nim_m3101_attach_fn(PCOFDM_TUNER_CONFIG_API pConfig)
{
#if (SYS_TUN_MODULE == ANY_TUNER)
    pConfig->tuner_type = SYS_TUN_TYPE;
#else
    pConfig->tuner_type = SYS_TUN_MODULE;
#endif
    pConfig->rev_id = M3100_REV_ID;
    pConfig->config_mode = 0;
    pConfig->work_mode = NIM_COFDM_ONLY_MODE;
    pConfig->ts_mode = NIM_COFDM_TS_SSI;
    nim_m31_attach(nim_dev_name[1], pConfig);
}

INT32 nim_m3101_attach_ext_fn(PCOFDM_TUNER_CONFIG_API pConfig)
{
#if (SYS_TUN_MODULE == ANY_TUNER)
    pConfig->tuner_type = SYS_TUN_TYPE;
#else
    pConfig->tuner_type = SYS_TUN_MODULE;
#endif
    pConfig->rev_id = M3100_REV_ID;
    pConfig->config_mode = 1;
    pConfig->work_mode = NIM_COFDM_ONLY_MODE;
    pConfig->ts_mode = NIM_COFDM_TS_SSI;
    nim_m31_attach(nim_dev_name[1], pConfig);
}

INT32 nim_m3101_dev_attach_ext(char *name, PCOFDM_TUNER_CONFIG_API pConfig)
{
    return nim_m31_attach(name, pConfig);
}

